package com.itheima.web.controller.pms;

import com.itheima.result.ResultData;
import com.itheima.service.pms.PmsProductAttributeCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/productAttribute/category")
@Slf4j
public class PmsProductAttributeCategoryController {
    @DubboReference
    private PmsProductAttributeCategoryService pmsProductAttributeCategoryService;

    /**
     * 添加商品属性分类
     * @param name
     * @return
     */
    @PostMapping("create")
    public ResultData addProductAttributeCategory(@RequestParam String name) {
        pmsProductAttributeCategoryService.addProductAttributeCategory(name);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 删除单个商品属性分类
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResultData deleteProductAttributeCategory(@PathVariable Long id) {
        return pmsProductAttributeCategoryService.deleteProductAttributeCategory(id);
    }

    /**
     * 分页获取所有商品属性分类
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public ResultData listProductAttributeCategory(@RequestParam Long pageNum , @RequestParam Long pageSize) {
        return pmsProductAttributeCategoryService.listProductAttributeCategory(pageNum , pageSize);
    }

    /**
     * 获取所有商品属性分类及其下属性
     * @return
     */
    @GetMapping("/list/withAttr")
    public ResultData listWithAttr() {
        return ResultData.ok("操作成功" , pmsProductAttributeCategoryService.listWithAttr());
    }

    /**
     * 修改商品属性分类
     * @param id
     * @param name
     * @return
     */
    @PostMapping("/update/{id}")
    public ResultData updateProductAttributeCategory(@PathVariable Long id , @RequestParam String name) {
        pmsProductAttributeCategoryService.updateProductAttributeCategory(id , name);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 获取单个商品属性分类信息
     * @param id
     * @return
     */
    @GetMapping("/category/{id}")
    public ResultData categoryId(@PathVariable Long id) {
        return ResultData.ok("" , pmsProductAttributeCategoryService.categoryId(id));

    }
}
